var DataSourceTree = function(options) {
	this._data 	= options.data;
	this._delay = options.delay;
};

DataSourceTree.prototype.data = function(options, callback) {
	var self = this;
	var $data = null;

	if(!("name" in options) && !("type" in options)){
		$data = this._data;//the root tree
		callback({ data: $data });
		return;
	}
	else if("type" in options && options.type == "folder") {
		if("additionalParameters" in options && "children" in options.additionalParameters)
			$data = options.additionalParameters.children;
		else $data = {};//no data
	}
	
	if($data != null)//this setTimeout is only for mimicking some random delay
		setTimeout(function(){callback({ data: $data });} , parseInt(Math.random() * 500) + 200);

	//we have used static data here
	//but you can retrieve your data dynamically from a server using ajax call
	//checkout examples/treeview.html and examples/treeview.js for more info
};

var tree_data_2 = {
	'pictures' : {name: 'Pictures', type: 'folder', 'icon-class':'red'}	,
	'music' : {name: 'Music',type: 'folder', 'icon-class':'orange'}	,
	'video' : {name: 'Video', type: 'folder', 'icon-class':'blue'}	,
	'documents' : {name: 'Documents', type: 'folder', 'icon-class':'green'}	,
	'backup' : {name: 'Backup', type: 'folder'}	,
	'readme' : {name: '<span class="glyphicon glyphicon-file grey"></span> ReadMe.txt', type: 'item'},
	'manual' : {name: '<span class="glyphicon glyphicon-book blue"></span> Manual.html', type: 'item'}
};
tree_data_2['music']['additionalParameters'] = {
	'children' : [
		{name: '<span class="glyphicon glyphicon-music blue"></span> song1.ogg', type: 'item'},
		{name: '<span class="glyphicon glyphicon-music blue"></span> song2.ogg', type: 'item'},
		{name: '<span class="glyphicon glyphicon-music blue"></span> song3.ogg', type: 'item'},
		{name: '<span class="glyphicon glyphicon-music blue"></span> song4.ogg', type: 'item'},
		{name: '<span class="glyphicon glyphicon-music blue"></span> song5.ogg', type: 'item'}
	]
};
tree_data_2['video']['additionalParameters'] = {
	'children' : [
		{name: '<span class="glyphicon glyphicon-film blue"></span> movie1.avi', type: 'item'},
		{name: '<span class="glyphicon glyphicon-film blue"></span> movie2.avi', type: 'item'},
		{name: '<span class="glyphicon glyphicon-film blue"></span> movie3.avi', type: 'item'},
		{name: '<span class="glyphicon glyphicon-film blue"></span> movie4.avi', type: 'item'},
		{name: '<span class="glyphicon glyphicon-film blue"></span> movie5.avi', type: 'item'}
	]
};
tree_data_2['pictures']['additionalParameters'] = {
	'children' : {
		'wallpapers' : {name: 'Wallpapers', type: 'folder', 'icon-class':'pink'},
		'camera' : {name: 'Camera', type: 'folder', 'icon-class':'pink'}
	}
};
tree_data_2['pictures']['additionalParameters']['children']['wallpapers']['additionalParameters'] = {
	'children' : [
		{name: '<span class="glyphicon glyphicon-picture green"></span> wallpaper1.jpg', type: 'item'},
		{name: '<span class="glyphicon glyphicon-picture green"></span> wallpaper2.jpg', type: 'item'},
		{name: '<span class="glyphicon glyphicon-picture green"></span> wallpaper3.jpg', type: 'item'},
		{name: '<span class="glyphicon glyphicon-picture green"></span> wallpaper4.jpg', type: 'item'}
	]
};
tree_data_2['pictures']['additionalParameters']['children']['camera']['additionalParameters'] = {
	'children' : [
		{name: '<span class="glyphicon glyphicon-picture green"></span> photo1.jpg', type: 'item'},
		{name: '<span class="glyphicon glyphicon-picture green"></span> photo2.jpg', type: 'item'},
		{name: '<span class="glyphicon glyphicon-picture green"></span> photo3.jpg', type: 'item'},
		{name: '<span class="glyphicon glyphicon-picture green"></span> photo4.jpg', type: 'item'},
		{name: '<span class="glyphicon glyphicon-picture green"></span> photo5.jpg', type: 'item'},
		{name: '<span class="glyphicon glyphicon-picture green"></span> photo6.jpg', type: 'item'}
	]
};


tree_data_2['documents']['additionalParameters'] = {
	'children' : [
		{name: '<span class="glyphicon glyphicon-file red"></span> document1.pdf', type: 'item'},
		{name: '<span class="glyphicon glyphicon-file grey"></span> document2.doc', type: 'item'},
		{name: '<span class="glyphicon glyphicon-file grey"></span> document3.doc', type: 'item'},
		{name: '<span class="glyphicon glyphicon-file red"></span> document4.pdf', type: 'item'},
		{name: '<span class="glyphicon glyphicon-file grey"></span> document5.doc', type: 'item'}
	]
};

tree_data_2['backup']['additionalParameters'] = {
	'children' : [
		{name: '<span class="glyphicon glyphicon-book brown"></span> backup1.zip', type: 'item'},
		{name: '<span class="glyphicon glyphicon-book brown"></span> backup2.zip', type: 'item'},
		{name: '<span class="glyphicon glyphicon-book brown"></span> backup3.zip', type: 'item'},
		{name: '<span class="glyphicon glyphicon-book brown"></span> backup4.zip', type: 'item'}
	]
};
var treeDataSource2 = new DataSourceTree({data: tree_data_2});